layui.use(['table','layer'],function(){
       var layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        table = layui.table;

    //客户列表展示
    var  tableIns = table.render({
        elem: '#customerList',
        even: true,
        url : ctx+'/customer/list',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limits : [10,20,40,80],
        limit : 10,
        toolbar: "#toolbarDemo",
        id : "customerListTable",
        cols : [[
            {field: "id", title:'客户Id',fixed:"left", width:70},
            {field: 'name', title: '客户姓名', minWidth:60, align:"center"},
            {field: 'number', title: '联系电话', align:'center',minWidth:80},
            {field: 'townName', title: '乡镇名称', align:'center',minWidth:150},
            {field: 'areaName', title: '村名称', align:'center',minWidth:150},
            {field: 'address', title: '详细地址', align:'center',minWidth:150},
            {title: '操作', minWidth:120, templet:'#customerListBar',fixed:"right",align:"left"}
        ]]
    });

    // 多条件搜索
    $(".search_btn").on("click",function(){
        table.reload("customerListTable",{
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
                customerName: $("input[name='customerName']").val(),
                customerNumber: $("input[name='customerNumber']").val(),
                townName: $("input[name='townName']").val(),
                areaName: $("input[name='areaName']").val()
            }
        })
    });

    /**
     * 行监听
     */
    table.on("tool(customer)", function(obj){
        var layEvent = obj.event;
        if(layEvent === "add") {
            window.parent.document.getElementById("customerId").value = obj.data.id;
            window.parent.document.getElementById("customerName").value = obj.data.name;
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        }
    });

});
